package com.fanshilz.flower2025.apps.admin.satoken;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpLogic;

public class StpAdminUtil {

    public static final String TYPE = "admin";

    public static final String current_key = "current_admin_user";

    public static StpLogic stpLogic = new StpLogic(TYPE);

    public static void checkLogin() {
        stpLogic.checkLogin();
    }

    public static void kickout(Long userId) {
        stpLogic.kickout(userId);
    }

    public static boolean isLogin() {
        return stpLogic.isLogin();
    }

    public static void login(AdminCurrentUser adminCurrentUser) {
        stpLogic.login(adminCurrentUser.getUserId());
        SaSession session = stpLogic.getSession();
        session.set(current_key, adminCurrentUser);
    }

    public static AdminCurrentUser currentUser() {
        return (AdminCurrentUser) stpLogic.getSession().get(current_key);
    }

    public static void logout() {
        stpLogic.logout();
    }

    public static void refreshCurrentUser(AdminCurrentUser adminCurrentUser) {
        SaSession session = stpLogic.getSession();
        session.set(current_key, adminCurrentUser);
    }

}
